package com.cheng.io.input;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;

/**
 * 解压流
 */
public class GZIPInputStreamTest01 {
    public static void main(String[] args) {
        try (
                // 读取压缩包
                GZIPInputStream inputStream = new GZIPInputStream(new FileInputStream("io/resources/test01.gz"));
                // 将解压后的文件，写入到文件中
                OutputStream outputStream = new FileOutputStream("io/resources/testFolder/test1/test01.txt");
        ) {
            // 边读边写
            byte[] bytes = new byte[1024];
            int readCount;
            while ((readCount = inputStream.read(bytes)) != -1) {
                outputStream.write(bytes, 0, readCount);
            }
            // 包装流需要手动刷新，节点流关闭时会自动刷新

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
